﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _02创建图形
{
    public class ArcExam
    {
        [CommandMethod("ArcDemo")]
        public void ArcDemo()
        {
            //Arc arc1 = new Arc();
            //arc1.Center = new Point3d(0, 0, 0);
            //arc1.StartAngle = -Math.PI / 4;
            //arc1.EndAngle = Math.PI / 4;
            //arc1.Radius = 100;
            //double startAngle = 45;
            //Arc arc2 = new Arc(new Point3d(50,50,0),20,startAngle.AngleToDegree(),90 );
            //Arc arc3 = new Arc(new Point3d(100, 100, 0), new Vector3d(0, 0, 1),20, Math.PI / 4, Math.PI / 2);

            Database db = HostApplicationServices.WorkingDatabase;
            //db.AddEnityToModelSpace(arc1, arc2, arc3);
            //db.AddArcToModelSapce(new Point3d(100, 100, 0), 50, 30, 270);
            //Point3d startPoint = new Point3d(100, 100, 0);
            //Point3d endPoint = new Point3d(200, 200, 0);
            //Point3d pointOnArc = new Point3d(150, 100, 0);
            //CircularArc3d cArc = new CircularArc3d(startPoint,pointOnArc,endPoint);

            //double radius = cArc.Radius;
            //Point3d center = cArc.Center;
            //Vector3d cs = center.GetVectorTo(startPoint);
            //Vector3d ce = center.GetVectorTo(endPoint);
            //Vector3d xvector = new Vector3d(1,0,0);

            //double startAngle = cs.Y > 0 ? xvector.GetAngleTo(cs) : -xvector.GetAngleTo(cs);
            //double endAngle = ce.Y > 0 ? xvector.GetAngleTo(ce) : -xvector.GetAngleTo(ce);
            //Arc arc = new Arc(center, radius, startAngle, endAngle);
            //db.AddEnityToModelSpace(arc);
            //Point3d startPoint = new Point3d(100, 100, 0);
            //Point3d endPoint = new Point3d(200, 200, 0);
            //Point3d pointOnArc = new Point3d(150, 100, 0);
            //db.AddArcToModelSapce(startPoint, pointOnArc, endPoint);

            //startPoint = new Point3d(100, 100, 0);
            //endPoint = new Point3d(200, 200, 0);
            //pointOnArc = new Point3d(150, 150, 0);
            //db.AddArcToModelSapce(startPoint, pointOnArc, endPoint);
            Point3d center = new Point3d(125, 175, 0);
            Point3d startPoint = new Point3d(100, 100, 0);
            //db.AddArcToModelSapce(center, startPoint, 135);
            Point3d point = new Point3d(200, 400, 0);
            double sAngle = center.GetAngleToXAxis(startPoint);
            double eAngle = center.GetAngleToXAxis(point);
            double r = startPoint.GetDistanceBetweenTwoPoint(center);
            Arc arc = new Arc(center, r, sAngle, eAngle);
            db.AddEnityToModelSpace(arc);
        }          

    }
}
